package com.sk.weichat.ui.me.redpacket;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.transition.Fade;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.githang.statusbar.StatusBarCompat;
import com.sk.weichat.R;
import com.sk.weichat.bean.redpacket.RedpacketDetailBean;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.ui.base.BaseActivity;
import com.sk.weichat.ui.me.PersonalCenterActivity;
import com.sk.weichat.ui.tool.WebViewActivity;
import com.sk.weichat.util.FrescoUtils;
import com.sk.weichat.util.ScreenUtil;

import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * @author lzs
 * @date 2019/10/11
 * Email:343067508@qq.com
 **/
public class PersonalRedPacketDetailsActivity extends BaseActivity {

    RedpacketDetailBean redpacketDetailBean;
    NumberFormat numberFormat = new DecimalFormat("0.00");

    public static final void startPersonalRedPacketDetailsActivity(Context context, RedpacketDetailBean redpacketDetailBean) {
        Intent intent = new Intent(context, PersonalRedPacketDetailsActivity.class);
        intent.putExtra(RedpacketDetailBean.RedpacketDetailBean_Key, redpacketDetailBean);
        context.startActivity(intent);
    }


//    public static final void startPersonalRedPacketDetailsActivityOptions(Activity context, RedpacketDetailBean redpacketDetailBean, Bundle options) {
//        Intent intent = new Intent(context, PersonalRedPacketDetailsActivity.class);
//        intent.putExtra(RedpacketDetailBean.RedpacketDetailBean_Key, redpacketDetailBean);
//        context.startActivity(intent, options);
//    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_redpacket_details);
        //setupWindowAnimations();
        //浅色状态栏字体图标
        StatusBarCompat.setLightStatusBar(getWindow(), false);
        ImageView ivBack = findViewById(R.id.iv_back);
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) ivBack.getLayoutParams();
        lp.topMargin += ScreenUtil.getStatusHeight(mContext);
        ivBack.setLayoutParams(lp);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.tv_record).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转交易记录
                String url = coreManager.getConfig().TRADE_RECORDE + "?access_token=" + coreManager.getSelfStatus().accessToken + "&time=" + System.currentTimeMillis() / 1000;
                WebViewActivity.start(mContext, url, false);
            }
        });
        redpacketDetailBean = getIntent() != null ? getIntent().getParcelableExtra(RedpacketDetailBean.RedpacketDetailBean_Key) : null;
        if (redpacketDetailBean != null) {
            TextView tvName = findViewById(R.id.tv_name);
            tvName.setText(redpacketDetailBean.getNickname() + " 的红包");

            TextView tvContent = findViewById(R.id.tv_content);
            tvContent.setText(redpacketDetailBean.getGreetings());

            TextView tvMoney = findViewById(R.id.tv_money);

            tvMoney.setText(numberFormat.format(redpacketDetailBean.getReceiveMoney()));

            //头像
            SimpleDraweeView ivAvatar = findViewById(R.id.iv_avatar);
            FrescoUtils.loadImage(ivAvatar, AvatarHelper.getAvatarUrl(redpacketDetailBean.getUserId() + "", true));
            ivAvatar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PersonalCenterActivity.start(mContext, redpacketDetailBean.getUserId() + "");
                }
            });

        }
    }

}
